package com.xe.icard;

import com.xe.framework.XEActivity;
import com.xe.framework.XEApp;

import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import com.xe.icard.R;

public class Main extends XEActivity implements OnClickListener, Runnable, AnimationListener{

	private View mWelcome;
	private Handler mHandler;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mWelcome = findViewById(R.id.welcome);
        mWelcome.setVisibility(View.VISIBLE);
        mHandler = new Handler();
        mHandler.postDelayed(this, 3000);
        //初始化事件控制
        View map_btn = findViewById(R.id.map_btn);
        map_btn.setOnClickListener(this);
        View photos_btn = findViewById(R.id.photos_btn);
        photos_btn.setOnClickListener(this);
        //启动背景音乐
//        Intent service = new Intent(BG_MUSIC);
//        bindService(service, new ServiceConnection() {
//			
//			@Override
//			public void onServiceDisconnected(ComponentName name) {
//				// TODO Auto-generated method stub
//				
//			}
//			
//			@Override
//			public void onServiceConnected(ComponentName name, IBinder service) {
//				// TODO Auto-generated method stub
//				
//			}
//		}, Service.BIND_AUTO_CREATE);
    }

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.map_btn:
			XEApp.getInstance().getActivityManager().next(Map.class, null, -1, R.anim.in_from_right, R.anim.out_to_left);
			break;
		case R.id.photos_btn:
			XEApp.getInstance().getActivityManager().next(Photos.class, null, -1, R.anim.in_from_right, R.anim.out_to_left);
			break;
		default:
			break;
		}
	}

	public void run() {
		Animation anim = AnimationUtils.loadAnimation(this, R.anim.open_book);
		anim.setFillAfter(true);
		anim.setFillEnabled(true);
		anim.setAnimationListener(this);
		mWelcome.startAnimation(anim);
	}

	public void onAnimationStart(Animation animation) {
	
	}

	public void onAnimationEnd(Animation animation) {
		// TODO Auto-generated method stub
		mWelcome.clearAnimation();
		mWelcome.setVisibility(View.GONE);
	}

	public void onAnimationRepeat(Animation animation) {
		
	}

	@Override
	protected void onDestroy() {
//		Intent service = new Intent(BG_MUSIC);
//		stopService(service);
		super.onDestroy();
	}
	
}
